/*!
 * \file TcpSocket.h
 * \brief Declares the TcpSocket class.
 */

#pragma once
#include "Socket.h"

namespace Networking
{
	class TcpSocket : public Socket
	{
	public:

		TcpSocket(void);

		virtual ~TcpSocket(void);

		TcpSocket * Accept(void);

		void Connect( const char * name, unsigned short port );

		void Listen( unsigned short port );

		void Send( const char * buffer, int length );

		int Receive( char * buffer, int length );

			/*!
			 * \brief Receives as Receive(char*, length), but waits for the full length of
			 * the given buffer to be filled before returning control.
			 *
			 * \param buffer is written with the data received from the socket.
			 * \param length is the exact number of bytes that will be written to buffer on
			 * successful return.
			 */
			virtual void ReceiveAll( char * buffer, int length );

			/*!
			 * \brief Describes the flows which are possible through a socket.
			 */
			enum FlowToShutDown
			{
				#ifdef WIN32
					Inbound = SD_RECEIVE,
					Outbound = SD_SEND,
					BothDirections = SD_BOTH
				#else
					Inbound = SHUT_RD,
					Outbound = SHUT_WR,
					BothDirections = SHUT_RDWR
				#endif
			};

			/*!
			 * \brief Causes all or part of a full-duplex connection on the socket to be
			 * shut down.
			 *
			 * Either or both of the flow directions can be shut down independently. Shutting
			 * down a socket is akin to ending communication gracefully.
			 *
			 * \param flow describes which classes of socket operations (inbound or outbound)
			 * should be shut down.
			 */
			void Shutdown(FlowToShutDown flow = BothDirections);

	protected:

	private:

		TcpSocket( SOCKET socket, struct sockaddr_in address );

	};
}
